package com.xuexiang.xuidemo.page.uilts.component;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Slider;
import ohos.agp.utils.Color;

import com.xuexiang.xui_lib.component.TitleBarLayout;
import com.xuexiang.xui_lib.util.ViewUtils;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.Page;
import com.xuexiang.xuidemo.util.XToastUtils;

/**
 * 控件Padding
 *
 * @since 2021-03-25
 */
@Page(name = "控件Padding", action = "utils.WidgetPaddingAbilitySlice")
public class WidgetPaddingAbilitySlice extends BasePageAbilitySlice implements Component.ClickedListener {
    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_utils_widget_padding;
    }

    @Override
    protected int getTitleBarId() {
        return ResourceTable.Id_title_bar;
    }

    @Override
    protected void onStart(Intent intent) {
        setUIContent(getLayoutId());
        Component leftLogo = findComponentById(ResourceTable.Id_left_logo);
        Component centerLogo = findComponentById(ResourceTable.Id_right_logo);
        Component rightLogo = findComponentById(ResourceTable.Id_center_logo);
        leftLogo.setClickedListener(this);
        centerLogo.setClickedListener(this);
        rightLogo.setClickedListener(this);
        Slider slider = findCastComponentById(ResourceTable.Id_padding_slider);
        slider.setProgressColor(new Color(Color.rgb(38, 172, 217)));
        slider.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int progress, boolean isFromUser) {
                ViewUtils.setPaddingLeft(leftLogo, progress);
                ViewUtils.setPaddingRight(leftLogo, progress);

                ViewUtils.setPaddingTop(rightLogo, progress);
                ViewUtils.setPaddingBottom(rightLogo, progress);
            }

            @Override
            public void onTouchStart(Slider slider) {
            }

            @Override
            public void onTouchEnd(Slider slider) {
            }
        });
        Slider clickSlider = findCastComponentById(ResourceTable.Id_click_slider);
        clickSlider.setProgressColor(new Color(Color.rgb(38, 172, 217)));
        int titleBarId = getTitleBarId();
        if (titleBarId > 0) {
            mTitleBar = (TitleBarLayout) findComponentById(titleBarId);
            mTitleBar.setTitleClickListener(this);
        }
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_left_logo:
                XToastUtils.toast("点击左边图片");
                break;
            case ResourceTable.Id_right_logo:
                XToastUtils.toast("点击右边图片");
                break;
            case ResourceTable.Id_center_logo:
                XToastUtils.toast("点击中间图片");
                break;
            default:
                // ignore
        }
    }
}
